import cv2
import dlib
camera = cv2.VideoCapture(0)
body_cascade = cv2.CascadeClassifier('haarcascade_fullbody.xml')
while True:
    success,img=camera.read()
    img_new = cv2.resize(img, (0, 0), fx=0.25, fy=0.25)
    process_this_frame = True
    if process_this_frame:
        # marks = face_recognition.face_locations(img_new)
        # codings = face_recognition.face_encodings(img_new, marks)
         # 图片转换成灰色（去除色彩干扰，让图片识别更准确）
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        bodies = body_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
        for (x, y, w, h) in bodies:
            cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
    cv2.imshow('Body Detection', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
camera.release()
cv2.destroyAllWindows()